import lombok.extern.slf4j.Slf4j;
import online.longzipeng.Springboot2DemoApplication;
import online.longzipeng.entity.User;
import online.longzipeng.mapper.UserMapper;
import online.longzipeng.service.UserService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

/**
 * @author lzp
 * @Date:2023/2/20
 * @description: 动态数据源测试Demo
 */
@SpringBootTest(classes = Springboot2DemoApplication.class,webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Slf4j
public class DynamicDataSourceDemo {

	@Autowired
	private UserService userService;
	@Autowired
	private UserMapper userMapper;

	@Test
	public void testDynamicDataSource(){
		userService.testDynamicDatasource();
	}

	/**
	 * 人人开源的动态数据源在springboot 1.x中添加在mapper文件上的注解，无法被切面捕获
	 */
	@Test
	public void test2() {
		User user = userMapper.getUser2();
		System.out.println(user.getNickName());
	}


}
